package com.huan.dml;

import com.huan.Call;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

public class PutDataAPI {

    //插入数据
    public static void putData(String tableName,String rowkey,String cf,String cn,String value) throws IOException {
        //1.获取表对象
        Connection conn = Call.conn;
        Table table = conn.getTable( TableName.valueOf( tableName ) );

        //2.创建Put对象 (就是创建rowkey)
        Put put = new Put( Bytes.toBytes( rowkey ) );

        //3.给put对象赋值
        put.addColumn( Bytes.toBytes( cf ),Bytes.toBytes( cn ),Bytes.toBytes( value ) );

        //4.插入数据
        table.put( put );

        //5.关闭表连接
        table.close();

    }

    public static void main(String[] args) throws IOException {
        putData("huan:stu","1001","info1","name","haoge");

        Call.close();

    }



}
